var deviceWidth
import store from '@/store/index'
setHtmlFontSize()
if (window.addEventListener) {
    window.addEventListener('resize', function () {
        setHtmlFontSize()
    }, false)
}

function setHtmlFontSize() {
    if (document.documentElement.clientWidth > 641) {
        //改变设备大小的判断 
        store.commit('changeEquipment', "pc");
        store.commit("changeClientW",document.documentElement.clientWidth);
        var doc = window.document,
            docEl = doc.documentElement;
        docEl.removeAttribute('data-dpr')
        // 1366是设计稿的宽度，当大于1366时采用1366宽度，比例也是除以13.66
        deviceWidth = document.documentElement.clientWidth > 1920 ? 1920 : document.documentElement.clientWidth
        // medium

        // document.getElementsByTagName('html')[0].style.cssText = 'font-size:' + deviceWidth / 19.2 + 'px '
        docEl.style.fontSize = deviceWidth / 19.2 + 'px '
    } else {
        store.commit('changeEquipment', "mobile");
        /* 设计图文档宽度 */
        var docWidth = 750;
        var doc = window.document,
            docEl = doc.documentElement,
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';

        var clientWidth = docEl.getBoundingClientRect().width;
        store.commit("changeClientW",document.documentElement.clientWidth);
        /* 8.55：小于320px不再缩小，11.2：大于420px不再放大 */
        docEl.style.fontSize = Math.max(20 * (clientWidth / docWidth), 8.55) * 5 + 'px ';


        /* 添加倍屏标识，安卓倍屏为1 */
        docEl.setAttribute('data-dpr', window.navigator.appVersion.match(/iphone/gi) ? window.devicePixelRatio : 1);

        if (/iP(hone|od|ad)/.test(window.navigator.userAgent)) {
            /* 添加IOS标识 */
            doc.documentElement.classList.add('ios');
            /* IOS8以上给html添加hairline样式，以便特殊处理 */
            if (parseInt(window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/)[1], 10) >= 8)
                doc.documentElement.classList.add('hairline');
        }
    }

}